import Vue from 'vue'
import VueRouter from 'vue-router'
import register from '@/views/register.vue'
import home from '@/views/home.vue'
import main from '@/views/main.vue'
import login from '@/views/login.vue'
import docter from '@/views/docter.vue'
import nurse from '@/views/nurse.vue'
import account from '@/views/account.vue'
import upload from '@/views/upload.vue'
import seeadoctor from '@/views/seeadoctor.vue'
import prescription from '@/views/prescription.vue'
import Medbuy from '@/views/Medbuy.vue'
import Medicion from '@/views/Medicion.vue'
import medsci from '@/views/medsci.vue'
import registerid from '@/views/registerid.vue'
import In_qu from '../views/In_qu.vue'
import in_pa_qu from '../views/in_pa_qu.vue'
import service from '../views/service.vue'
import patientIn from '../views/patientIn.vue'
import prescriptionIn from '../views/prescriptionIn.vue'
import operationReser from '../views/operationReser.vue'
import operation from '../views/operation.vue'
import Asset from '../views/Asset.vue'
import registersel from '@/views/registersel.vue'
import count from '@/views/count.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: login
  }, 
  {
    path: '/main',
    name: 'main',
    component: main,
    children: [
      {
        path: '/count',
        name: 'count',
        component: count
      },
      {
        path: '/Asset',
        name: 'Asset',
        component: Asset,
      },
      {
        path: '/registerid',
        name: 'registerid',
        component: registerid,
      },
      {
        path: '/registersel',
        name: 'registersel',
        component: registersel
      },
      {
        path: '/medsci',
        name: 'medsci',
        component: medsci
      },
      {
        path: '/In_qu',
        name: 'In_qu',
        component: In_qu
      }, {
        path: '/in_pa_qu',
        name: 'in_pa_qu',
        component: in_pa_qu
      }, {
        path: '/service',
        name: 'service',
        component: service,
        children: [
          {
            path: '/patientIn',
            name: 'patientIn',
            component: patientIn
          },
          {
            path: '/prescriptionIn',
            name: 'prescriptionIn',
            component: prescriptionIn
          },
          {
            path: '/operationReser',
            name: 'operationReser',
            component: operationReser
          },
          {
            path: '/operation',
            name: 'operation',
            component: operation
          },
        ]
      },
      {
        path: '/docter',
        name: 'docter',
        component: docter
      },
      {
        path: '/nurse',
        name: 'nurse',
        component: nurse
      },
      {
        path: '/account',
        name: 'account',
        component: account
      },
      {
        path: '/Medbuy',
        name: 'Medbuy',
        component: Medbuy
      },
      {
        path: '/Medicion',
        name: 'Medicion',
        component: Medicion
      }, {
        path: '/prescription',
        name: 'prescription',
        component: prescription
      },
      {
        path: '/seeadoctor',
        name: 'seeadoctor',
        component: seeadoctor
      }]
  }, {
    path: '/home',
    name: 'home',
    component: home
  }, {
    path: '/register',
    name: 'register',
    component: register
  }, {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/upload',
    name: 'upload',
    component: upload
  }

]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  let userStr = localStorage.getItem('loginAccount');
  let user = JSON.parse(userStr);
  if (to.path == '/login' || to.path == '/register' || user != null) {
    next();
  } else {
    alert("您还未登陆");
    next('/login')
  }
})

export default router
